function lstinf$(a$,b$,c$)
  adra=1:adrb=1:blngt=len(b$):d$=""
  while adrb<=blngt
    if mid$ (a$,adra,1)=mid$ (b$,adrb,1) then:adrb+=1:end if
    adra=adra+1
    end while
  while mid$(a$,adra,1)<>left$(c$,1)
    d$=d$+mid$(a$,adra,1):adra=adra+1
    end while
  lstinf$=d$
  end function

function vldc(a$)
  t0$="!"+a$+".0.0.0."
  t1$=lstinf$(t0$,"!",".")
  t2$=lstinf$(t0$,".",".")
  t3=10^(len(t2$))
  vldc=val(t1$)+(val(t2$)/t3)
  end function

dim chfq[16],chvl[16]

finp$="_.csv"
if argc>2 then:finp$=argv(2):end if

print"56676D20"
print"FFFFFF00"
print"61010000"
print"0000000000000000"
print"DE050000"
print"002B0500"
print"A7000000"

print"00000000"
print"32000000"
print"000000000000000000000000"
print"8C000000"
print"0000000000000000"

print"0000000000000000"
print"00000000000000000000000000000000"
print"00000000000000000000000000000000"
print"00000000000000000000000000000000"
print"0000000000000000"

print"00004040"
print"00000000000000000000000000000000"
print"00000000000000000000000000000000"
print"00000000000000000000000000000000"
print"000000000000000000000000"
print

print"B30000"
print"B3168F B315FF B31477"
print"B30000 B30200 B30700 B30C20"
print"B311F7 B31200"
print"B30100 B30600 B30A00"
print"B32000 B32111 B32222 B32333"
print"B32444 B32555 B32666 B32777"
print"B32888 B32999 B32AAA B32BBB"
print"B32CCC B32DDD B32EEE B32FFF"
print"B30A80 B30D59 B30A00"
print"B3013F B302F5"
print"B3030B"
print"B3013F"
print"B30486"
print"B3063F B307F5 B30872"
print"B3063F B30986"
print"B30BFF B30A80 B30B3F B30E87"
print"B3103F B311F5 "
print"B31215 B31380"
print"B3103F"

print"B38000"
print"B3968F B395FF B39477"
print"B38000 B38200 B38700 B38C20"
print"B391F7 B39200"
print"B38100 B38600 B38A00"
print"B3A000 B3A111 B3A222 B3A333"
print"B3A444 B3A555 B3A666 B3A777"
print"B3A888 B3A999 B3AAAA B3ABBB"
print"B3ACCC B3ADDD B3AEEE B3AFFF"
print"B38A80 B38D59 B38A00"
print"B3813F B382F5"
print"B3830B"
print"B3813F"
print"B38486"
print"B3863F B387F5 B38872"
print"B3863F B38986"
print"B38BFF B38A80 B38B3F B38E87"
print"B3903F B391F5 "
print"B39215 B39380"
print"B3903F"


print

lct=0

open finp$ for input as #1
while eof(1)=0
  file input #1,txrd$
  setcaption("b:"+str$(lct)):lct+=1
  if mid$(txrd$,1,1)="[" then:
    if mid$(txrd$,2,1)="f" then:
      chid=val(mid$(txrd$,3,2))
      chid=chid mod 8 'rp2c33x8 has 8 channels
      chfqv=vldc(lstinf$(txrd$,":","]"))
      if (chid mod 4)=2 then:chfqv+=1:end if '- channel 3 is 1 octave lower
      chfqv2=(2047-int(31.25*2^(8-chfqv)))
      if chfqv2>2047 then:chfqv2=2047:end if
      if chfqv2<0 then:chfqv2=0:end if
      chchrfq$=right$("000"+hex$(chfqv2),3)
      if int(chid/4)=0 then
        txrgo$="B3"+right$("00"+hex$(4+5*(chid mod 4)),2)+"8"+mid$(chchrfq$,1,1)
        txrgo$+=" B3"+right$("00"+hex$(3+5*(chid mod 4)),2)+mid$(chchrfq$,2,2)
      else
        txrgo$="B3"+right$("00"+hex$(128+4+5*(chid mod 4)),2)+"8"+mid$(chchrfq$,1,1)
        txrgo$+=" B3"+right$("00"+hex$(128+3+5*(chid mod 4)),2)+mid$(chchrfq$,2,2)
        end if

      print ucase$(txrgo$)
      end if
    if mid$(txrd$,2,1)="v" then:
      chid=val(mid$(txrd$,3,2))
      chid=chid mod 8 'rp2c33x8 has 8 channels
      chvlv=vldc(lstinf$(txrd$,":","]"))*0x40
      chchrvl$=right$("00"+hex$(chvlv),2)
      if int(chid/4)=0 then
        txrgo$="B3"+right$("00"+hex$(1+5*(chid mod 4)),2)+chchrvl$
      else
        txrgo$="B3"+right$("00"+hex$(128+1+5*(chid mod 4)),2)+chchrvl$
        end if

      print ucase$(txrgo$)
      end if
    if mid$(txrd$,2,3)="wvb" then:
      wvblv=vldc(lstinf$(txrd$,":","]"))
      wvblv2=wvblv*44100
      wvblv3a=wvblv2 mod 65536
      wvblv3b=int(wvblv2/65536)
      wvblv3as$=ucase$(right$("0000"+hex$(wvblv3a),4))
      for ii=1 to wvblv3b:print"61FFFF":next
      print "61"+mid$(wvblv3as$,3,2)+mid$(wvblv3as$,1,2)


      end if

    end if
  wend
print:print "66":print
close #1


